package com.ccsoft.zknote.pojo.system;


/**
 * @ClassName:JsonResult
 * @Description: 2023年7月11日 改版，新增属性 success。之前前端通过判断 code 是否请求成功
 *               替换为布尔类型 success 更直观。code 保留备用。
 * @Author:chanchaw
 * @Date:2019-12-07 19:38
 * @Version:1.0
 **/
public class JsonResult {
    private Boolean success;
    private Integer code;
    private String msg;
    private Object data;

    public static JsonResult ok(){
        JsonResult jr = new JsonResult();
        jr.success = true;
        return jr;
    }

    public static JsonResult ok(Object data){
        JsonResult jr = new JsonResult();
        jr.success = true;
        jr.data = data;
        return jr;
    }

    public static JsonResult ok(Object data,String msg){
        JsonResult jr = new JsonResult();
        jr.success = true;
        jr.data = data;
        jr.msg = msg;
        return jr;
    }

    public static JsonResult error(String msg){
        JsonResult jr = new JsonResult();
        jr.success = false;
        jr.msg = msg;
        return jr;
    }


    public JsonResult() {
    }

    public JsonResult(Object data) {
        this.success = true;
        this.data = data;
    }

    public JsonResult(Boolean success, Integer code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "success=" + success +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}